﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cards;

namespace TexasHoldem.Hands
{
    public class TwoPair : HandBase
    {
        public override HandType HandType
        {
            get { return HandType.TwoPair; }
        }

        public Rank highPairRank;
        public Rank lowPairRank;

        public TwoPair(Card[] orderedCards)
            : base(orderedCards)
        {
            var groupedRanks = orderedCards.GroupBy(card => card.Rank).OrderBy(grouping => grouping.Key).ToArray();
            highPairRank = groupedRanks[0].Key;
            lowPairRank = groupedRanks[1].Key;
        }

        protected override int CompareByRank(HandBase other)
        {
            var twoPair = other as TwoPair;

            int result = this.highPairRank.CompareTo(twoPair.highPairRank);
            if (result != 0)
            {
                return result;
            }

            result = this.lowPairRank.CompareTo(twoPair.lowPairRank);
            if (result != 0)
            {
                return result;
            }
            
            return base.CompareByRank(other);
        }
    }
}